.TH std::stack::size 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::stack::size \- std::stack::size

.SH Synopsis
   size_type size() const;

   Returns the number of elements in the container adaptor. Equivalent to return
   c.size().

.SH Parameters

   \fI(none)\fP

.SH Return value

   The number of elements in the container adaptor.

.SH Complexity

   Constant.

.SH Example


// Run this code

 #include <algorithm>
 #include <cassert>
 #include <stack>

 int main()
 {
     std::stack<int> stack;

     assert(stack.size() == 0);

     const int count = 8;

     for (int i = 0; i != count; ++i)
         stack.push(i);

     assert(stack.size() == count);
 }

.SH See also

   empty   checks whether the container adaptor is empty
           \fI(public member function)\fP
   size
   ssize   returns the size of a container or array
   \fI(C++17)\fP \fI(function template)\fP
   (C++20)
